using Digitalmes.Domain.Entities.Mes.Productions;

namespace Digitalmes.Application.Mes.Traceability.Workstations.Queries;

/// <summary>
/// 查询产品在指定工位上指定的生产工艺步骤数据的查询命令。
/// </summary>
/// <param name="StepExecutionId">过点数据 Id</param>
public sealed record GetDownloadDataQuery(long StepExecutionId) : IRequest<IResult<List<ProcessExportDataDto>>>;

internal sealed class GetDownloadDataQueryHandler(IRepository<ProdStepExecution> stepExecutionRepo) : IRequestHandler<GetDownloadDataQuery, IResult<List<ProcessExportDataDto>>>
{
    public async Task<IResult<List<ProcessExportDataDto>>> Handle(GetDownloadDataQuery request, CancellationToken cancellationToken)
    {
        // 查找执行记录（可重复过站）
        var items = await stepExecutionRepo.GetListAsync(m => m.Id == request.StepExecutionId, cancellationToken);
        return Result.From(items.Adapt<List<ProcessExportDataDto>>());
    }
}
